// 1.导入模块
import Vue from 'vue'
import VueRouter from 'vue-router'

// 路由懒加载
const home = () => import('../views/Home')
const goods = () => import('../views/Goods')
const cart = () => import('../views/Cart')
const profile = () => import('../views/Profile')

// 2.安装
Vue.use(VueRouter)
const VueRouterReplace = VueRouter.prototype.replace
VueRouter.prototype.replace = function replace (to) {
  return VueRouterReplace.call(this, to).catch(err => err)
}

// 3.配置映射关系
const routes = [
  {
    path: '',
    redirect: '/home'
  },
  {
    path: '/home',
    component: home
  }
  ,
  {
    path: '/goods',
    component: goods
  }
  ,
  {
    path: '/cart',
    component: cart
  }
  ,
  {
    path: '/profile',
    component: profile
  }
]
const router = new VueRouter({
  routes
})

// 4.导出
export default router